//-----------------------------------------------------------------------
// <copyright file="ConversationCollection.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Microsoft.Live.Messenger
{
    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Diagnostics;
    using Microsoft.Live.Core;

    /// <summary>
    /// Represents a collection of conversations.
    /// </summary>
    /// <remarks>
    /// Use ConversationCollection to manage active conversations for a User, and to create new conversations.
    /// </remarks>
    public sealed class ConversationCollection : Collection
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ConversationCollection"/> class.
        /// </summary>
        /// <param name="User">The associated User.</param>
        internal ConversationCollection(object obj, User user)
            : base(obj, user)
        {
        }

        /// <summary>
        /// Creates a conversation with the specified instant messaging address.
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public Conversation Create(
            IMAddress address)
        {
            if (address == null)
            {
                throw ExceptionHelper.CreateArgumentNullException("address");
            }

            return this.User.CreateConversation(address);
        }

        /// <summary>
        /// Gets the <c>Conversation</c> at the specific index.
        /// </summary>
        /// <param name="index">The zero-based index of the <c>Conversation</c> to get.</param>
        /// <returns>The <c>Conversation</c> at the specified index.</returns>
        public Conversation this[int index]
        {
            get { return (Conversation)this.GetItem(index); }
        }

        internal override object FindOrCreate(MessengerEntity entity)
        {
            return this.User.ConversationFactory.FindOrCreate(entity);
        }
    }
}